package com.zhongkai.controller;

import com.zhongkai.app.service.SectionService;
import com.zhongkai.model.utils.ZhongkaiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 部门管理
 * */
@Controller
public class SectionController {


    @Autowired
    private SectionService sectionService;


    /**
     * 部门添加
     *
     * @param name      部门名称
     * @param plane     部门电话
     * @param principal 部门负责人
     * @param phone     负责人电话
     */
    @RequestMapping(value = "/branch/add", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult addSection(String name, String plane, String principal, String phone) {

        ZhongkaiResult result = sectionService.addSection(name,plane,principal,phone);

        return result;
    }


    /**
     * 部门修改
     *
     * @param id      部门id
     * @param name      部门名称
     * @param plane     部门电话
     * @param principal 部门负责人
     * @param phone     负责人电话
     */
    @RequestMapping(value = "/branch/update", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult updateSection(
            @RequestParam(defaultValue = "0") Integer id, String name, String plane, String principal, String phone) {

        ZhongkaiResult result = sectionService.updateSection(id,name,plane,principal,phone);

        return result;
    }



    @RequestMapping(value = "/branch/remove", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult removeSection(
            @RequestParam(defaultValue = "0") Integer id) {

        ZhongkaiResult result = sectionService.removeSection(id);

        return result;
    }

    @RequestMapping(value = "/branch/list", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult listSection(
            @RequestParam(defaultValue = "0")Integer page, @RequestParam(defaultValue = "0")Integer rows) {

        ZhongkaiResult result = sectionService.listSection(page,rows);

        return result;
    }
}
